<template>
  <GFormCreator ref="form" :config="conf">
    <template #btn>
      <el-button type="primary" @click="create">创建人员</el-button>
      <el-button @click="reset">重置</el-button>
    </template>
  </GFormCreator>
</template>

<script>
import conf from './pageConf'
import { doCreateUser } from '@/api/user'
export default {
  data() {
    return {
      conf,
    }
  },
  created() {
    // 该方法作为局部方法，后续销毁后再次执行可重新bind，相同的全局方法不可二次bind
    this.conf.rules.confirmPwd[0].validator = function (rule, value, callback) {
      console.log('123', value, this.ruleForm.password)
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.ruleForm.password) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
  },
  methods: {
    create() {
      this.$refs.form.valid(async (data) => {
        delete data.confirmPwd
        await doCreateUser(data)
      })
    },
    reset() {},
  },
}
</script>
